<?php

namespace backend\controllers;

use bc\controller\BackendController;
use bc\model\baby\ConfigModel;
use bc\model\BabyModel;
use bc\util\backend\Page;
use bc\model\baby\ActivityModel;
use bc\ar\MActiveRecord;

class BabyController extends BackendController
{
	
	protected $jobs = [
			1 => [
					'val' => 1,
					'job' => '哒哒哒黑猫警长',
					'description' => 'bibibi！不许动！我已经报警了！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_19.jpg'
			],
			2 => [
					'val' => 2,
					'job' => '哗哗哗大作家',
					'description' => '悬梁刺股，奋笔疾书，深藏功与名！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_0.jpg'
			],
			3 => [
					'val' => 3,
					'job' => '特种兵欧巴',
					'description' => '上天遁地我无所畏惧，只是要借助飞机，挖掘机。',
					'img' => 'http://wx.zhishimama.com/baby/img/a_11.jpg'
			],
			4 => [
					'val' => 4,
					'job' => '老戏骨演员',
					'description' => '如果再给我一次机会，我想熟读倒背演员自我修养！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_9.jpg'
			],
			5 => [
					'val' => 5,
					'job' => '蒙面歌手',
					'description' => '立白歌手之我是洗衣粉！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_15.jpg'
			],
			6 => [
					'val' => 6,
					'job' => '灵魂演奏家',
					'description' => '台下一分钟，台上十年功！谁叫我天赋异禀！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_8.jpg'
			],
			7 => [
					'val' => 7,
					'job' => '全能运动员',
					'description' => '运动只是我的业余爱好，其实我是表！情！帝！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_4.jpg'
			],
			8 => [
					'val' => 8,
					'job' => '相声艺术家',
					'description' => '我的天哪！你是传说中的小小小岳岳嘛！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_17.jpg'
			],
			9 => [
					'val' => 9,
					'job' => '小卷毛法官',
					'description' => '我发如雪好像方便面！公正之锤砸呀砸呀砸！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_16.jpg'
			],
			10 => [
					'val' => 10,
					'job' => '奥特曼宇航员',
					'description' => 'Yes Sir，我在火星种土豆！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_6.jpg'
			],
			11 => [
					'val' => 11,
					'job' => '大大大科学家',
					'description' => '哟哟切克闹！我为祖国造大炮！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_13.jpg'
			],
			12 => [
					'val' => 12,
					'job' => '霸道癌CEO',
					'description' => '这片鱼塘我包了！从此升任白富美，迎娶CEO，走向人生巅峰！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_2.jpg'
			],
			13 => [
					'val' => 13,
					'job' => '医生爸爸',
					'description' => '杀！华佗给了你个桃！华佗又给了你个桃！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_7.jpg'
			],
			14 => [
					'val' => 14,
					'job' => '帅帅都叫兽',
					'description' => 'You are my destiny！You are my destiny...',
					'img' => 'http://wx.zhishimama.com/baby/img/a_14.jpg'
			],
			15 => [
					'val' => 15,
					'job' => 'IT程序猿',
					'description' => 'Just do IT.要做就要做IT!听说Nike要干掉我！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_1.jpg'
			],
			16 => [
					'val' => 16,
					'job' => '大长腿模特',
					'description' => '大海啊都是水！我啊只有腿！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_5.jpg'
			],
			17 => [
					'val' => 17,
					'job' => '潇洒诗人',
					'description' => '生活不只是眼前的苟且,还有诗和远方',
					'img' => 'http://wx.zhishimama.com/baby/img/a_12.jpg'
			],
			18 => [
					'val' => 18,
					'job' => '金牌主持人',
					'description' => '有人模仿我的脸，有人模仿我的面，但模仿不了我的...这酸爽~',
					'img' => 'http://wx.zhishimama.com/baby/img/a_3.jpg'
			],
			19 => [
					'val' => 19,
					'job' => '跳跳跳舞蹈家',
					'description' => '完美！',
					'img' => 'http://wx.zhishimama.com/baby/img/a_10.jpg'
			],
			20 => [
					'val' => 20,
					'job' => '加盒饭导演',
					'description' => '我不仅主导自己的人生，还能导导别人de，别动物de，别植物de...',
					'img' => 'http://wx.zhishimama.com/baby/img/a_18.jpg'
			],
				
	];
	
	
	public function actionIndex()
	{
		
		$controller = \Yii::$app->controller->id;
		
		echo $controller;
		exit;
		
		$view = [];
		$model = new BabyModel();
		
		$params = '1 = 1';
		
		$page = $this->get('page', 1);
		$model->sort = 'job_count desc, play_date asc';
		$list = $model->getList($params, $page, self::PAGE_SIZE);
		
		$total = $model->getTotal($params);
		
		$pagination = new Page($total, self::PAGE_SIZE);
		
		$view['list'] = $list;
		$view['pagination'] = $pagination;
		
		
		return $this->render('index', $view);
	}
	
	
	public function actionEdit()
	{
		$id = $this->get('id');
		if(!$id)
			$this->redirect('/');
		
		$page = $this->get('page', 1);
		
		
		$model = new BabyModel();
		$row = $model->getRowById($id);
		
		if(!$row)
			$this->redirect('/');
		
		$list = [];
		
		$activityModel = new ActivityModel();		
		$params['baby_id'] = $row['id'];
		
		$activityModel->sort = 'activity_id DESC';
		$list = $activityModel->getList($params, $page, self::PAGE_SIZE);
		$total = $activityModel->getTotal($params);
		
		$pagination = new Page($total, self::PAGE_SIZE);
		
		$view['row'] = $row;
		$view['list'] = $list;
		$view['pagination'] = $pagination;
		$view['jobs'] = $this->jobs;
		
		return $this->render('edit', $view);
	}
	
	
	/**
	 * 页面分享统计
	 */
	public function actionStatistic()
	{
		$view = [];
		
		$dao = new MActiveRecord();
		$sql = 'select id, page_id, count(page_id) as total from bc_baby_page_statistic group by page_id';
		$result = $dao->getDb()->createCommand($sql)->queryAll();
		$view['result'] = $result;
		
		return $this->render('statistic', $view);
	}
	
	public function actionJob()
	{
		$configModel = new ConfigModel();
		$row = $configModel->getRowById('1');
		$view['row'] = $row;
		return $this->render('job', $view);
	}
	
	public function actionJobsave()
	{
		if($this->getRequest()->isPost )
		{
			$configModel = new ConfigModel();
			$num = $this->post('num');
			$configModel->modify(['num' => $num], 1);
		}
		$output['msg'] = '修改成功！';
		$output['url'] = '/baby/job';
		$this->forward($output);
	}
}

